<?php
// https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/
class Solution {

    /**
     * 最低点买入， 最高点卖出
     * @param Integer[] $prices
     * @return Integer
     */
    function maxProfit($prices) {
        $maxProfit = 0;
        $minCost = PHP_INT_MAX;
        foreach ($prices as $day_price) {
            $minCost = min($minCost, $day_price);
            $maxProfit = max($day_price - $minCost, $maxProfit);
        }
        return $maxProfit;
    }
}